package com.uenpay.im.ui.old.activity.bankcard;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * 银行卡列表
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class BankCardListInvokeItem extends BaseHttpInvokeItem {
	public class BankCardListInvokeItemResult extends HttpInvokeResult {
		public ArrayList<String> cardList = new ArrayList<String>();
	}

	public BankCardListInvokeItemResult getOutPut() {
		return (BankCardListInvokeItemResult) GetResultObject();
	}

	public BankCardListInvokeItem() {
		String url = APIConfiguration.getBaseUrl() + "Communal/Bank/bankList?"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		BankCardListInvokeItemResult result = new BankCardListInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONArray array = json.optJSONArray("data");
			if (array != null && array.length() > 0) {
				for (int i = 0, size = array.length(); i < size; i++) {
					result.cardList.add(array.optString(i));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
